// ExceptionClassExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

class CMathError
{
private:
	char message[30];
	
public:
	CMathError(const char* p_msg)
	{
		strcpy(message,p_msg);
	}

	const char* getMessage() const {return message;};
};


double divide(int a,int b) throw (CMathError)
{
	if(b < 0)
	{
		throw CMathError("Denominator is negative!");
	}

	if(b == 0)
	{
		throw CMathError("Devided by 0!");
	}

	return ((double)a/b);
}


int _tmain()
{
	int x,y;
	bool flag = false;

	do
	{
		try
		{
			cout<<"Enter two positive integers:";
			cin>>x>>y;
			cout<<x<<"/"<<y<<"="<<divide(x,y)<<endl;
			flag = true;
		}
		catch(const CMathError &r_err)
		{
			cerr<<r_err.getMessage()<<endl;
		}
	
	} while(!flag);
	
	
	return 0;
}

